<template>
	<view>
		<chat-navbar></chat-navbar>
		<scroll-view :style="{height:height+'px'}" scroll-y :show-scrollbar="true" :scroll-with-animation="true">	
			<!-- 搜索框 -->
			<view style="display: flex;justify-content: center;background-color: #FFFFFF;padding: 20rpx 0;">
				<input style="width: 90%;height: 70rpx;border-radius: 40rpx;background-color: #F5F6F7;padding: 0 40rpx;color: #333333;text-align: center;" value="🔍搜索" />
			</view>
			<user-chat-list></user-chat-list>
		</scroll-view>
	</view>
</template>

<script>
	import chatNavbar from "./chat-navbar.vue";
	import userChatList from "./user-chat-list.vue";
	import {
		mapState,
		mapMutations,
		mapActions
	} from 'vuex'
	import myWebsocket from "../../common/myWebsocket.js"
	export default {
		computed: mapState(['isLogin', 'loginUserInfo']),
		components: {
			chatNavbar,
			userChatList
		},
		onLoad(){
			// this.init()
		},
		onShow() {
			if(!this.isLogin){
				uni.navigateTo({
					url: '/pages/login/login'
				});
			}
			// console.log(JSON.stringify(myWebsocket.Msg("123", this.$myEnum.type.IMAGE,null)))
			// console.log(this.$myEnum.type.IMAGE)
		},
		data() {
			return {
				height: this.swiperHeight,
			}
		},
		methods: {
			init(){
				if(this.isLogin){
					//形成登录消息
					var msg = myWebsocket.Msg("",this.$myEnum.type.TEXT,null);
					var msgContent = myWebsocket.MsgContent(this.$myEnum.action.CONNECT,this.loginUserInfo.id,"",msg,this.loginUserInfo)
					//连接 socket 并发送连接消息
					myWebsocket.connectSocket(msgContent)
				
					/**
					 * 打开数据库，如果这里没打开，则在登录页面，登录之后打开
					 */
					this.$mySqlite.openComDB(this.loginUserInfo.id,res => {
						console.log(res);
					})
				}
			}
		}
	}
</script>

<style>

</style>
